package com.hoyue.classroom.controller;

import com.hoyue.classroom.bean.Course;
import com.hoyue.classroom.service.MemberService;
import com.hoyue.classroom.service.ScoreService;
import com.hoyue.system.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 空白
 * @version 1.0
 * Create by 2019/09/03 09:10
 */
@Controller
@RequestMapping("/score")
public class ScoreController {

    private String prefix = "/score";

    @Autowired
    MemberService memberService;

    @Autowired
    ScoreService scoreService;

    /**
     * 显示学生成绩
     * @param model
     * @param session
     * @return
     */
    @GetMapping("/list")
    public String index(Model model, HttpSession session) {
        Course course = (Course) session.getAttribute("course");
        // 查询课程所有成员
        List<User> student = memberService.ListMember(course.getId());
        for (User stu : student) {
            // 查询每个学生的成绩（包含多个种类的成绩及不同批次的成绩）
            stu.setScoreList(scoreService.getScore(stu.getId(), course.getId()));
        }
        return prefix + "/score";
    }
}
